package com.lin.fengxiu.vo;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.domain.Page;

import java.util.List;

/**
 * @ClassName Paging
 * @Description TODO
 * @Author wushaopei
 * @Date 2021/3/14 12:02
 * @Version 1.0
 */
@Getter
@Setter
@NoArgsConstructor
public class Paging<T> {
    /**
     * @Description 总数量
     */
    private Long total;

    /**
     * @Description 总数量
     */
    private Integer count;

    /**
     * @Description 页数
     */
    private Integer page;

    /**
     * @Description 总页数
     */
    private Integer totalPage;

    /**
     * @Description 页面数据
     */
    private List<T> items;

    /**
     *
     * @param pageT
     */
    public Paging(Page<T> pageT) {
        this.initPageParameters(pageT);
//      拿到数据返回的真实数据
        this.items = pageT.getContent();
    }

    /**
     *
     * @param pageT
     */
    void initPageParameters(Page<T> pageT){
        this.total = pageT.getTotalElements();
        this.count = pageT.getSize();
        this.page = pageT.getNumber();
        this.totalPage = pageT.getTotalPages();
    }
}
